
function createObject() {
	var r = new Job(BasePath.get()+"/livcos.org/web/editor/CreateObject.job")
	r.addFormData(document.forms[0]);
  r.onCompleted = function() {
    var msg = document.getElementById("message");
    var root = this.dom.documentElement;
    var action = Dom(root).getChild("create");
    if (action) {
    	// successful
	    var objId = action.getAttribute("objId");
	    msg.innerHTML = 'Object <a href="'+BasePath.get()+objId+'">'+objId+'</a> successfully created!<br>'+
	    'Click <a href="'+BasePath.get()+'/livcos.org/web/data.html?ref='+objId+'">here</a> to edit.';
    }
    else {
    	// failure
      var objId = document.getElementById("objId").value;
      var ex = Dom(root).getChild("exception");
	    msg.innerHTML = 'Failed to create object <a href="'+BasePath.get()+objId+'">'+objId+'</a>!<br/><br/>';
      msg.innerHTML += 'Exception: '+Dom(Dom(ex).getChild("message")).getTextContent()+'<br/><br/>';
      msg.innerHTML += 'see the complete <a href="javascript:Dom(\'response\').toggle();">Response</a>';
	    this.transform(window.resource_metaXslt, document.getElementById("response"));
    }
  };
  r.start();
}

function setTmpl(objId) {
	Dom("tmplId").element.value = objId;
}

new EventListener(window, "load", function(evn) {
  Dom("objId").setRefAutoComplete("/");
  Dom("tmplId").setRefAutoComplete("/");
	window.resource_metaXslt = new Resource(BasePath.get()+"/livcos.org/web/style/meta_content.xsl");
	window.resource_metaXslt.load();
});

